package com.sam.widget.headerBar;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.View;

import com.sam.widget.R;
import com.sam.widget.button.StateImageButton;

/**
 * Created by Administrator on 2016/6/13.
 */
public class LeftImgTitleBar extends BaseTitleBar{

    private Drawable leftImgSrcDrawable,leftImgBgDrawable;
    private StateImageButton leftImgBtn;

    public LeftImgTitleBar(Context context) {
        this(context,null);
    }

    public LeftImgTitleBar(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public LeftImgTitleBar(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    protected void getAttrs(AttributeSet attrs) {
        super.getAttrs(attrs);
        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.LeftImgTitleBar);
        leftImgSrcDrawable=ta.getDrawable(R.styleable.LeftImgTitleBar_leftImgSrcDrawable);
        leftImgBgDrawable=ta.getDrawable(R.styleable.LeftImgTitleBar_leftImgBgDrawable);
        ta.recycle();
    }

    @Override
    protected void findView() {
        super.findView();
        leftImgBtn = new StateImageButton(context);
        if(leftImgSrcDrawable != null){
            leftImgBtn.setImageDrawable(leftImgSrcDrawable);
        }
        if(leftImgBgDrawable != null){
            leftImgBtn.setBackgroundDrawable(leftImgBgDrawable);
        }
    }

    public View getLeftView() {
        return leftImgBtn;
    }
}
